// https://www.qidka.com/api
// http://v2.qidka.com/api

const install = (Vue, vm) => {
	// 全局配置
	Vue.prototype.$u.http.setConfig({
		baseUrl: 'http://v2.qidka.com/api',
		showLoading: false,
		loadingMask: false,
		originalData: true
	});

	// 请求拦截
	Vue.prototype.$u.http.interceptor.request = (config) => {
		let token = vm.$store.state.token
		if (token) {
			config.header.Authorization = 'Bearer ' + token
		} else {
			config.header.Authorization = ''
		}
		return config;
	}

	// 响应拦截
	Vue.prototype.$u.http.interceptor.response = (res) => {
		if (res.data.success) {
			return res
		} else if (res.data.code == 401) {
			vm.$msg('请先登录', 1000, true).then(res => {
				vm.$goto('/pages/login/login')
			})
		} else {
			vm.$msg('出了点小问题')
		}
	}
	
	// 结束
}

export default {
	install
}